package org.budo.jdbc.dao.resultset.handler;

import java.sql.ResultSet;

import org.budo.jdbc.dao.ResultSetHandler;
import org.budo.support.javax.sql.util.ResultSetUtil;

/**
 * @author limingwei
 */
public class IntegerResultSetHandler implements ResultSetHandler<Integer> {
    private Integer columnIndex;

    /**
     * @param columnIndex
     */
    public IntegerResultSetHandler(Integer columnIndex) {
        this.columnIndex = columnIndex;
    }

    @Override
    public Integer handleResultSet(ResultSet resultSet) {
        if (null == resultSet) {
            return null;
        }

        if (ResultSetUtil.next(resultSet)) {
            return ResultSetUtil.getInt(resultSet, this.getColumnIndex());
        }

        return null;
    }

    public Integer getColumnIndex() {
        return this.columnIndex;
    }
}
